package com.baor.config;

import org.springframework.cloud.gateway.filter.factory.StripPrefixGatewayFilterFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.*;

@Configuration
public class GatewayConfig {
    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder, StripPrefixGatewayFilterFactory stripPrefix) {
        RouteLocatorBuilder.Builder route = builder.routes()
                .route("movie", x -> {
                    return x.path("/movie_server/**").filters(f -> {
                        f.stripPrefix(1);
                        return f;
                    }).uri("lb://movies");
                })
                .route("sys", x -> {
                    return x.path("/sys_server/**").filters(f -> {
                        f.stripPrefix(1);
                        return f;
                    }).uri("lb://smovies");
                });
        return route.build();
    }
}
